/*
 * @Author: ygnnli 1585923072@qq.com
 * @Date: 2024-08-15 20:23:08
 * @LastEditors: ygnnli 1585923072@qq.com
 * @LastEditTime: 2024-08-19 18:43:58
 * @FilePath: /bitrpc/source/test_client.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "../../common/detail.hpp"
#include "../../client/rpc_client.hpp"

void callback(const Json::Value &result)
{
    ILOG("callback  result: %d ", result.asInt());
}
int main()
{
    bitrpc::client::RpcClient client(true, "127.0.0.1", 8080); // 注册中心地址，服务地址，服务端口

    Json::Value params, result;
    params["num1"] = 11;
    params["num2"] = 22;
    bool ret = client.call("Add", params, result);
    if (ret != false)
    {
        ILOG("result: %d ", result.asInt());
    }
    ILOG("同步调用完毕!!");
    // 异步调用
    bitrpc::client::RpcCaller::JsonAsyncResponse res_future; // 异步调用结果
    params["num1"] = 55;
    params["num2"] = 21;
    ret = client.call("Add", params, res_future);
    if (ret != false)
    {
        result = res_future.get(); // 获取异步调用结果
        ILOG("result: %d ", result.asInt());
    }
    ILOG("异步调用完毕!!");
    // 回调调用
    params["num1"] = 555;
    params["num2"] = 21;
    ret = client.call("Add", params, callback);
    DLOG("---------");

    ILOG("回调调用完毕!!");
    std::this_thread::sleep_for(std::chrono::seconds(20));

    return 0;
}